﻿using SqlSugar;

namespace Zhp.SqlSugar.Entity
{
    /// <summary>
    /// 只包含主键，删除额外字段
    /// </summary>
    /// <typeparam name="TKey"></typeparam>
    public abstract class RootEntity<TKey> : RootEntity
    {
        /// <summary>
        /// 主键
        /// </summary>
        [SugarColumn(IsPrimaryKey = true, ColumnDescription = "ID主键")]
        public virtual TKey Id { get; set; }

    }

    /// <summary>
    /// 基础公共字段
    /// </summary>
    public abstract class RootEntity : IRootEntity
    {
        /// <summary>
        /// 是否删除
        /// </summary>
        [SugarColumn(IsNullable = true, ColumnDescription = "软删除(1:删除，0:未删除)")]
        public virtual bool IsDeleted { get; set; } = false;

        /// <summary>
        /// 可携带其他数据新增
        /// </summary>
        [SugarColumn(IsIgnore = true)]
        public List<IRootEntity> InsertExtraEntity { get; set; } = new List<IRootEntity>();

        /// <summary>
        /// 可携带其他数据更新
        /// </summary>
        [SugarColumn(IsIgnore = true)]
        public List<IRootEntity> UpdateExtraEntity { get; set; } = new List<IRootEntity>();

        /// <summary>
        /// 可携带其他数据一起删除
        /// </summary>
        [SugarColumn(IsIgnore = true)]
        public List<IRootEntity> DeleteExtraEntity { get; set; } = new List<IRootEntity>();
    }

    public interface IRootEntity : IDeleted
    {
        /// <summary>
        /// 可携带其他数据新增
        /// </summary>
        public List<IRootEntity> InsertExtraEntity { get; set; }

        /// <summary>
        /// 可携带其他数据更新
        /// </summary>
        public List<IRootEntity> UpdateExtraEntity { get; set; }

        /// <summary>
        /// 可携带其他数据一起删除
        /// </summary>
        public List<IRootEntity> DeleteExtraEntity { get; set; }
    }

    /// <summary>
    /// 继承此接口实体自动拥有逻辑删除功能
    /// </summary>
    public interface IDeleted
    {
        public bool IsDeleted { get; set; }
    }
}
